package com.haelth.comman;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

import org.jsoup.Connection;
import org.jsoup.Connection.Method;
import org.jsoup.Jsoup;
import org.jsoup.nodes.DataNode;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.haelth.comman.basic.BaseConnection;
import com.haelth.models.formdata.LoginFormData;

public class Connectchawa extends BaseConnection {
	// Initialize FormData
	LoginFormData form = new LoginFormData();

	public Map<String, String> Connect() {
		try {
			Connection.Response res = Jsoup
					.connect("https://www.chahwa.com.tw/user.php")
					.data("username", form.getUsername(), "password",
							form.getPassword(), "wsrc", form.getWsrc(), "act",
							form.getAct(), "back_act", form.getBack_act())
					.method(Method.POST).execute();
			cookies = res.cookies();
			Document doc2 = Jsoup
					.connect(
							"http://www.chahwa.com.tw/order.php?act=query&&drug=泰克&hid=&emt_drug=&itemiid2=&source=or&1412777909900900")
					.cookies(cookies).get();

			Elements jsElms = doc2.getElementsByTag("script");

			doc2 = Jsoup.parse(jsElms.html());
			System.out.println(doc2);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return cookies;

	}

	public static void main(String[] args) {
		Connectchawa con = new Connectchawa();
		con.Connect();

	}
}
